<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>疫苗固有信息管理</title>
<meta name="decorator" content="default" />
<script type="text/javascript">
	var batchType = '${batchType}';
	$(document).ready( function() {
		//$("#name").focus();
		$("#inputForm").validate( {
			submitHandler : function(form) {
				postOrderDetil(form);
			}
		});

		$('#vaccineId').change(function() {
			var str = $("#vaccineId").val();
			var com = $("#companyCode").val();
			if (str == '请选择') {
				$("#companyCode").find("option").remove();
				$("#companyCode").select2();
				initCompanyName(com);
				return;
			}
			var url = "${ctx}/vaccinate/bsVaccineBatchno/getCompanyVaccId";
			var select = '<option value="">--请选择--</option>';
			$("#companyCode").find("option").remove();
			$("#companyCode").select2();
			$.ajax({
				url : url,
				data : {
					"id" : $("#vaccineId").val()
				},
				success : function(data) {
					data = $.parseJSON(data);
					for (var i = 0; i < data.length; i++) {
						select += "<option>" + data[i].companyName + "</option>";
					}
					$("#companyCode").append(select);
				}
			});
		});
	});

	function postOrderDetil(form) {//表单保存时  将此方法中的数据尽行保存
		debugger;
		if(!$("#companyName").valid() || $("#companyName").val()==""){
			layer.msg('添加失败，检查数据是否正确!');
			//$("#companyName").next('label[data=update]').text("生产企业不能为空!").show();
			return;
		}
		if(!checkBatchno()){
			return;
		}
		var vaccineName = $("#vaccineId").find("option:selected").text();
		//var companyName = $("#companyCode").find("option:selected").text();
		$("#vaccineName").val(vaccineName);
		$("#vaccNameAll").val(vaccineName);
		$("#businessName").val(vaccineName);
		//$("#companyName").val(companyName);
		layer.confirm('确定保存？', {
			btn : [ '保存', '取消' ]
		//按钮
		}, function() {
			layer.load(2);
			loading('正在提交，请稍等...');
			form.submit();
		});
	}
	
	function closeIframe() {
		var index = parent.layer.getFrameIndex(window.name);
		if (index) {
			parent.layer.close(index);
		} else {
			window.location.href = "${ctx}/vaccinate/bsVaccineBatchno/manageBatchno?batchType=2";
		}
	}
    //重置
	function rese(){			
		location.reload();
	}
	
	function checkBatchno(){
		debugger;
		//var str =$(thi).val();
		if($("#batchno").val()==""){
			$("#batchno").next('label[data=update]').text("请输入批号!").show();
			return false;
		}else{
			var flag =false;
			var url = "${ctx}/vaccinate/bsVaccineBatchno/checkBatchno";
			$.ajax({
				url :url,
				async: false,
				data :{"batchno":$("#batchno").val(),
						"vaccineId":$("#vaccineId").val(),
	                    "companyCode":$("#companyCode").val()
	                    } ,
				success : function(data){
					if(data.length>0){
						$("#batchno").next('label[data=update]').text("该批次已存在!").show();
					}else{
						$("#batchno").next('label[data=update]').text("").hide();
						flag = true;
					}
				}
			});
			return flag;
		}
	}

	function change() {
		$(".input-text").val($('#companyCode').val());
	}
</script>

<style type="text/css">
body {
	padding: 20px;
}

.minWidth {
	min-width: 500px;
}

@media ( min-width : 789px) and (max-width: 1098px) {
	.secondChild {
		margin-left: 0
	}
}

[class*="span"] {
	margin-left: 0px;
}

.box {
	position: relative;
	height: 26px;
}

.input-text {
	width: 296px;
	height: 26px;
	outline-color: #ccc;
	padding: 0px;
	position: absolute;
	z-index: 1;
}

.selected {
	width: 330px;
	height: 28px;
	border: 1px solid #e6e0e0;
	outline-color: #ccc;
	padding: 0px;
	border-radius: 6px;
	position: absolute;
	z-index: 0;
}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active">
			<a>增加注射器批次号</a>
		</li>
	</ul>
	<br/>
	<form:form id="inputForm" modelAttribute="bsVaccineBatchno"
		action="${ctx}/vaccinate/bsVaccineBatchno/save" method="post" class="form-horizontal">
		<input type="hidden" name="type" id="type" value = "1"/>
		<form:input type="hidden" id="batchType" path="batchType" />
		<form:input type="hidden" id="createOrgCode" path="createOrgCode"/>
		<form:input type="hidden" id="createOrgName" path="createOrgName"/>
		<form:input type="hidden" id="vaccineName" path="vaccineName"/>
		<form:input type="hidden" id="vaccNameAll" path="vaccNameAll"/>
		<form:input type="hidden" id="businessName" path="businessName"/>
		<%-- <form:input type="hidden" id="companyName" path="companyName"/> --%>
		<sys:message content="${message}" />
		<div class="row-fluid">
			<div class="control-group span6 minWidth" data-line="line1">
				<label class="control-label"><font color="red">*</font> 注射器类型：</label>
				<div class="controls">
					<select id="vaccineId" name="vaccineId" class="span7 required">
						<option value="">--请选择--</option>
						<c:forEach items="${fns:getDictList('batch_syringe_type')}"
							var="dict">
							<option value="${dict.value}">${dict.label}</option>
						</c:forEach>
					</select> 
				</div>
			</div>

			<div class="control-group span6 minWidth" data-line="line2">
				<label class="control-label"><font color="red">*</font> 生产企业：</label>
				<div class="controls" id="app" class="box">
					<select id="companyCode" name="companyCode" class="selected" onchange="change()">
					</select>
					<input class="input-text required" id="companyName" name="companyName" type="text"/>
					<label hidden="true"  class="error" data="update"></label>
				</div>
			</div>
		</div>

		<div class="row-fluid">
			<div class="control-group span6 minWidth">
				<label class="control-label"><font color="red">*</font> 规格：</label>
				<div class="controls">
					<select name="spec" id="spec" class="span7 required">
						<option value="">--请选择--</option>
						<c:forEach items="${fns:getDictList('syringe_spec')}" var="dict">
							<option value="${dict.value}">${dict.label}</option>
						</c:forEach>
					</select>
				</div>
			</div>

			<div class="control-group span6 minWidth">
				<label class="control-label"><font color="red">*</font> 批号：</label>
				<div class="controls">
					<input type="text" id="batchno" name="batchno" maxlength="32" class="span7  required" onblur="checkBatchno()" />
					<label hidden="true"  class="error" data="update"></label>
				</div>
			</div>
			<div class="row-fluid">
				<div class="control-group span6 minWidth">
					<label class="control-label"><font color="red">*</font> 有效日期至：</label>
					<div class="controls">
						<input id="outBoundDate" name="outBoundDate" type="text" maxlength="20" class="span7 Wdate required"
							value="" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});" />
					</div>
				</div>
			</div>

			<div class="form-actions">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="保存" />
				<input id="btnReset" class="btn" type="button" onclick="rese()" value="重置" />
				<!-- <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)" /> -->
				<input id="btnClose" class="btn" type="button" onclick="closeIframe()" value="关闭" />
			</div>
		</div>
	</form:form>
</body>
</html>